package cn.cvs.controller;

import cn.cvs.pojo.SysUser;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * 第一个Spring MVC控制器
 */
@Controller
@RequestMapping(value = "/hello")
public class HelloController{
    Logger logger=Logger.getLogger(HelloController.class);

    @RequestMapping("/hello")
    public String hello(){
        return "hello";
    }

    @RequestMapping("/show")
    public String show(Model model, @RequestParam String account){
        model.addAttribute("account",account);
        return "show";
    }


//    @RequestMapping("/hello")
//    public ModelAndView hello(@RequestParam String realName) throws Exception{
//        logger.info("你好【"+realName+"】欢迎来到Spring MVC课堂。");
//        ModelAndView modelAndView=new ModelAndView();
//        modelAndView.addObject("realName",realName);
//        modelAndView.setViewName("hello");
//        return modelAndView;
//    }
    /**
     * Spring MVC
     * @return
     * @throws Exception
     */
//    @RequestMapping(value = "/hello")
//    public String hello(@RequestParam(required = false) String realName) throws Exception{
//        logger.info("你好"+realName+"欢迎来到Spring MVC课堂。");
//        //跳转到hello页面
//        return "hello";
//    }

//    @RequestMapping(value = "/hello2")
//    public String hello2(Model model,@RequestParam String realName) throws Exception{
//        logger.info("你好【"+realName+"】欢迎来到Spring MVC课堂。");
//        model.addAttribute("realName",realName);
//        model.addAttribute(realName);
//        SysUser sysUser=new SysUser();
//        sysUser.setRealName(realName);
//        model.addAttribute("currentUser",sysUser);
//        model.addAttribute(sysUser);
//        return "hello";
//    }

//    @RequestMapping("/hello3")
//    public String hello3(Map<String,Object> map,@RequestParam String realName) throws Exception{
//        logger.info("你好【"+realName+"】欢迎来到Spring MVC课堂。");
//        map.put("realName",realName);
//        return "hello";
//    }
}
